package com.infra.micro.quartz.controller;

import com.infra.common.resp.Page;
import com.infra.common.resp.Response;
import com.infra.micro.quartz.domain.entity.QuartzJobLogPO;
import com.infra.micro.quartz.domain.service.QuartzJobLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Quartz调度日志服务
 *
 * @author PD
 */
@RestController
@RequestMapping("/api/quartz/log")
@Api(tags = {"Quartz日志管理服务"})
public class QuartzJobLogController {
    @Resource
    private QuartzJobLogService quartzJobLogService;

    @ApiOperation(value = "根据日志ID查询详情", notes = "根据日志ID查询详情", produces = "application/json")
    @ApiImplicitParam(name = "logId", value = "作业ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @GetMapping(value = "/{logId}")
    public Response<QuartzJobLogPO> queryById(@PathVariable("logId") Long logId) {
        return quartzJobLogService.queryById(logId);
    }

    @ApiOperation(value = "根据日志ID删除日志", notes = "根据日志ID删除日志", produces = "application/json")
    @ApiImplicitParam(name = "logId", value = "作业ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @DeleteMapping(value = "/{logId}")
    public Response<Integer> deleteById(@PathVariable("logId") Long logId) {
        return quartzJobLogService.deleteById(logId);
    }

    @ApiOperation(value = "根据日志ID集合批量删除", notes = "根据日志ID集合批量删除", produces = "application/json")
    @ApiImplicitParam(name = "logId", value = "作业ID", dataType = "Long", dataTypeClass = Long.class, allowMultiple = true, paramType = "body", required = true)
    @DeleteMapping(value = "")
    public Response<Integer> batchDeleteByIds(@RequestBody List<Long> logIds) {
        return quartzJobLogService.batchDeleteByIds(logIds);
    }

    @ApiOperation(value = "根据jobId查日志列表", notes = "根据jobId查日志列表", produces = "application/json")
    @ApiImplicitParam(name = "jobId", value = "作业ID", dataType = "Long", dataTypeClass = Long.class, paramType = "path", required = true)
    @GetMapping("/{jobId}/list")
    public Response<Page<QuartzJobLogPO>> queryListByJobId(@PathVariable("jobId") Long jobId, Page<QuartzJobLogPO> page) {
        return quartzJobLogService.queryListByJobId(jobId, page);
    }

    @ApiOperation(value = "根据条件查询日志列表", notes = "根据条件查询日志列表", produces = "application/json")
    @GetMapping("/list")
    public Response<Page<QuartzJobLogPO>> queryListByConf(Page<QuartzJobLogPO> page) {
        return quartzJobLogService.queryListByConf(page);
    }
}
